home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / getpatch.000 < prev    next >
Text File  |  1996-11-17  |  4KB  |  117 lines

  1. #!/bin/sh
  2. #
  3. # $Id: getpatch,v 2.0 1996/01/15 06:07:04 hamilton Exp hamilton $
  4. #
  5. #
  6. # getpatch written by Jon Hamilton (hamilton@mixcom.com) in a fit of
  7. # boredom.  A crude hack, but it works.
  8. #
  9. # This will check to see which version of the kernel you are running, and
  10. # get all the patches between there and the current release.  If you're
  11. # not running linux, or if you want to specify some other "current version",
  12. # you can say so on the command line, e.g.  ``getpatch 1.3.51'' will cause
  13. # it to behave as if you are currently running 1.3.51.
  14. #
  15. # $PATCH_FTPDIR can be set if you don't like the default location, which
  16. # is ~/kernel_patches.  The script will make sure that you don't already
  17. # have a patch before ftping it.
  18. #
  19. # Be careful; there's not much error checking in this script.  Use at
  20. # your own risk, etc.
  21. #
  22. # There are also some limitations, namely in the way $GETLIST is built, but
  23. # it works for most "sane" uses.
  24. #
  25. # You may do with this as you like, but please leave the attribution and
  26. # the instructional comments above in anything you modify or distribute.
  27. #
  28. ###############################################################################
  29. # (This is getpatch v2.1 by Kent Robotti 7-5-96) (The same as getpatch v2.0 
  30. # by jon hamilton (I just configured it for you, so that it's ready to run.)
  31. #
  32. # ~# chmod u+x getpatch   <-Make getpatch executable.)
  33. #
  34. # You should have a /root/.netrc  <-Create this file and put this line in it.>
  35. #
  36. # default login anonymous password joe@soho.ios.com   <-your@email.address.)
  37. #
  38. # ~# getpatch        <-Start getpatch, after your connected slip/ppp etc.)
  39. # The kernel patches will be put in.-> /usr/src/linux/scripts
  40. # /usr/src/linux/scripts# chmod u+x patch-kernel   <-Make executable.)
  41. # # patch-kernel     <-Start applying those patches.)
  42. #
  43. # It's set to start with kernel 2.0, if you have kernel 1.3.something, you'll
  44. # have to change below.> MAJORVER=1.3 (It's best to update to 2.0.something.)  
  45. ###############################################################################
  46.  
  47. PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
  48. # You'll need to change this if you're after the 1.2.x kernels (or 1.5.x, when
  49. # those come out)
  50.  
  51. MAJORVER=2.0
  52.  
  53. # Might be good net.citizenship to change these to reflect a mirror, too.
  54.  
  55. KERNELHOST=ftp.funet.fi
  56. KERNELDIR=/pub/Linux/kernel/src/v$MAJORVER
  57.  
  58. PATCH_FTPDIR=${PATCH_FTPDIR:-/usr/src/linux/scripts}
  59. TMPFILE=$PATCH_FTPDIR/data
  60. export KERNELHOST KERNELDIR TMPFILE PATH PATCH_FTPDIR
  61.  
  62. ftpget(){
  63.   cd $PATCH_FTPDIR
  64.   echo "getting $* => $PATCH_FTPDIR"
  65.   ftp -v $KERNELHOST << DONE
  66.   cd $KERNELDIR
  67.   prompt
  68.   mget $*
  69. DONE
  70. }
  71.  
  72. get_current_release(){
  73. ftp -v $KERNELHOST > $TMPFILE <<CEASE_ALREADY
  74. cd $KERNELDIR
  75. dir
  76. CEASE_ALREADY
  77.  
  78. CURRENT_RELEASE=`grep LATEST-IS $TMPFILE | awk '{print $9}' | cut -c11-`
  79. echo $CURRENT_RELEASE
  80. }
  81.  
  82. if [ -n "$1" ] ; then
  83.   CURRENT_VERSION=$1
  84. elif [ "`uname -s`" = "Linux" ] ; then
  85.   CURRENT_VERSION=`uname -r`
  86. else
  87.   echo "You're not running linux on this machine; please specify"
  88.   echo "which kernel version you have on the command line."
  89.   exit 1
  90. fi
  91.  
  92. CURRENT_RELEASE=`get_current_release`
  93. echo "Current release is $CURRENT_RELEASE, you're running $CURRENT_VERSION."
  94.  
  95. if [ "$CURRENT_RELEASE" != "$CURRENT_VERSION" ] ; then
  96. # build a list of which patches we need to get
  97. # start with the current release and work backwards
  98.   if [ ! -f "$PATCH_FTPDIR/patch-$CURRENT_RELEASE.gz" ] ; then
  99.     GETLIST=patch-$CURRENT_RELEASE.gz
  100.   else
  101.     unset GETLIST # might as well be paranoid
  102.   fi
  103.   SUCKED_MINOR=`echo $CURRENT_RELEASE | cut -c5-`
  104.   HAVE_MINOR=`echo $CURRENT_VERSION | cut -c5-`
  105.   while [ "$HAVE_MINOR" -ne "$SUCKED_MINOR" ] ; do
  106.     SUCKED_MINOR=`expr $SUCKED_MINOR - 1`
  107.     if [ ! -f $PATCH_FTPDIR/patch-$MAJORVER.$SUCKED_MINOR.gz ] ; then
  108.       GETLIST="$GETLIST patch-$MAJORVER.$SUCKED_MINOR.gz"
  109.     fi
  110.   done
  111.   if [ -z "$GETLIST" ] ; then
  112.     echo "You already have all the patches up to $CURRENT_RELEASE."
  113.   else
  114.        ftpget $GETLIST
  115.   fi
  116. fi
  117.